{extend name="layout/main" /}

{block name="header"}

{/block}

{block name="content"}
<section class="panel">
    <header class="panel-heading">
        <h4>代券比例</h4>
    </header>
    <div class="panel-body" style="padding-bottom: 50px">
        <table class="table table-bordered table-striped no-margin">
            <thead>
            <tr>
                <th class="text-center">序号</th>
                <th class="text-center">日期</th>
                <th class="text-center">固定价格</th>
                <th class="text-center">实时价格(CNY)</th>
                <th class="text-center">日最高</th>
                <th class="text-center">日最低</th>
                <th class="text-center">涨跌幅(%)</th>
                <th class="text-center">倍数</th>
                <th class="text-center">操作</th>
            </tr>
            </thead>
            <tbody>
            {foreach $list as $key=>$config}
            <tr>
                <td class="text-center" style="vertical-align: middle; ">{$key+1}</td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="date"  style="text-align: center" id="_date{$config['id']}" class="form-control" value="{$config['date']}"></td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="number" id="_today_ratio{$config['id']}" style="text-align: center" class="form-control"
                           value="{$config['today_ratio']}">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="number" id="_ratio{$config['id']}" style="text-align: center" class="form-control"
                           value="{$config['ratio']}">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="number" READONLY id="_day_max{$config['id']}" style="text-align: center" class="form-control"
                           value="{$config['day_max']}">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="number" READONLY id="_day_min{$config['id']}" style="text-align: center" class="form-control"
                           value="{$config['day_min']}">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="number" id="_day_ratio{$config['id']}" style="text-align: center" class="form-control"
                           value="{$config['day_ratio']}">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="number" id="_ratio_times{$config['id']}" style="text-align: center" class="form-control"
                           value="{$config['ratio_times']}">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <a onclick="updateConfig(this)"
                       data-id="{$config['id']}"
                       data-date="{$config['date']}"
                       data-ratio="{$config['ratio']}"
                       data-today_ratio="{$config['today_ratio']}"
                       data-day_max="{$config['day_max']}"
                       data-day_min="{$config['day_min']}"
                       data-day_ratio="{$config['day_ratio']}"
                       data-ratio_times="{$config['ratio_times']}"
                       class="btn btn-xs btn-primary">确认修改</a>
                </td>
            </tr>
            {/foreach}
            <tr>
                <td class="text-center" style="vertical-align: middle; "></td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="date"  style="text-align: center" id="date" class="form-control" value=""></td>
                <td class="text-center" style="vertical-align: middle; ">
                    <input type="text"  style="text-align: center" id='ratio' class="form-control" value="">
                </td>
                <td class="text-center" style="vertical-align: middle; ">
                    <a onclick="addConfig(this)" class="btn btn-xs btn-primary">确认添加</a>
                </td>
            </tr>
            </tbody>
        </table>

    </div>
</section>
{/block}

{block name="footer"}

<script>
    function addConfig(e) {
        var date = $('#date').val();
        var ratio = $('#ratio').val();

        $.post("{:url('ratioadd')}", {date: date,ratio: ratio}, function (data) {
            if (data.code == 1) {
                main.waringAlert(data.message);
            } else {
                main.waringAlert(data.message);
                window.location.reload();
            }
        }, 'json')
    }
    function updateConfig(e) {
        var id = $(e).attr('data-id');

        var date1 = $(e).attr('data-date');
        var date = $('#_date' +id).val();
        var ratio1 = $(e).attr('data-ratio');
        var ratio = $('#_ratio' +id).val();
        var day_max = $('#_day_max' +id).val();
        var day_min = $('#_day_min' +id).val();
        var day_ratio = $('#_day_ratio' +id).val();
        var today_ratio = $('#_today_ratio' +id).val();
        var ratio_times = $('#_ratio_times' +id).val();
        $.post("{:url('ratioupd')}", {
            id: id,
            date: date ,
            ratio:ratio,
            day_max:day_max,
            day_min:day_min,
            day_ratio:day_ratio,
            today_ratio:today_ratio,
            ratio_times:ratio_times,

        }, function (data) {
            if (data.code == 1) {
                main.waringAlert(data.message);
            } else {
                main.waringAlert(data.message);
                window.location.reload();
            }
        }, 'json')
    }
</script>
{/block}